package com.gigi.datageniebackendmaster.controller;

import com.gigi.datageniebackendmaster.common.BaseResponse;
import com.gigi.datageniebackendmaster.common.IdRequest;
import com.gigi.datageniebackendmaster.model.request.GenChartRequest;
import com.gigi.datageniebackendmaster.model.request.ListChartRequest;
import com.gigi.datageniebackendmaster.model.vo.GenChartVO;
import com.gigi.datageniebackendmaster.model.vo.MyChartVO;
import com.gigi.datageniebackendmaster.service.ChartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;

@Api(tags = "图表管理")
@RestController
@RequestMapping("chart")
public class ChartController {

    @Autowired
    private ChartService chartService;

    @ApiOperation(value = "生成图表（异步mq）")
    @PostMapping("gen/async/mq")
    public BaseResponse<Boolean> genChartAsyncMq(@Valid GenChartRequest request,
                                                 @RequestPart("file") MultipartFile file,
                                                 HttpServletRequest httpServletRequest) throws IOException {
        return chartService.genChartAsyncMq(request, file, httpServletRequest);
    }

    @ApiOperation(value = "生成图表（异步）")
    @PostMapping("gen/async")
    public BaseResponse<Boolean> genChartAsync(@Valid GenChartRequest request,
                                               @RequestPart("file") MultipartFile file,
                                               HttpServletRequest httpServletRequest) throws IOException {
        return chartService.genChartAsync(request, file, httpServletRequest);
    }

    @ApiOperation(value = "生成图表（同步）")
    @PostMapping("gen")
    public BaseResponse<GenChartVO> genChart(@Valid GenChartRequest request,
                                             @RequestPart("file") MultipartFile file,
                                             HttpServletRequest httpServletRequest) throws IOException {
        return chartService.genChart(request, file, httpServletRequest);
    }

    @ApiOperation(value = "列表")
    @PostMapping("list")
    public BaseResponse<MyChartVO> list(@RequestBody ListChartRequest request, HttpServletRequest httpServletRequest) {
        return chartService.list(request, httpServletRequest);
    }

    @ApiOperation(value = "删除")
    @PostMapping("del")
    public BaseResponse<Boolean> del(@RequestBody @Valid IdRequest request, HttpServletRequest httpServletRequest) {
        return chartService.del(request, httpServletRequest);
    }

}
